import Student from './student.js';
let {element,$} = layui;
export default class Manange{
    constructor(next){
        this.render();
        this.handle(next);
    }
    render(){
        let template = `
        <div class="layui-layout layui-layout-admin">
            <div class="layui-header">
                <div class="layui-logo layui-hide-xs layui-bg-black">
                    朗沃学生管理系统
                </div>
               
                <ul class="layui-nav layui-layout-right">
                    <li
                        class="layui-nav-item layui-hide layui-show-md-inline-block"
                    >
                        <a id="username" href="javascript:;">

                        </a>
                        <dl class="layui-nav-child">
                            <dd><a href="">Your Profile</a></dd>
                            <dd><a href="">Settings</a></dd>
                            <dd><a id="logout" href="javascript:;">Sign out</a></dd>
                        </dl>
                    </li>
                    <li
                        class="layui-nav-item"
                        lay-header-event="menuRight"
                        lay-unselect
                    >
                        <a href="javascript:;">
                            <i class="layui-icon layui-icon-more-vertical"></i>
                        </a>
                    </li>
                </ul>
            </div>

            <div class="layui-side layui-bg-black">
                <div class="layui-side-scroll">
                    <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
                    <ul class="layui-nav layui-nav-tree" lay-filter="studentNav">
                       
                        <li class="layui-nav-item">
                            <a href="#manage/student">学生管理</a>
                        </li>
                        <li class="layui-nav-item">
                            <a href="#manage/class">班级管理</a>
                        </li>
                        <li class="layui-nav-item">
                            <a href="#manage/teacher">老师管理</a>
                        </li>
                    </ul>
                </div>
            </div>

            <div class="layui-body">
                <!-- 内容主体区域 -->
                <div id="content" style="padding: 15px">
                    
                </div>
            </div>

            <div class="layui-footer">
                <!-- 底部固定区域 -->
            </div>
        </div>
        `;
        $("#root").html(template);
    }
    handle(next){
        element.render();
        $.ajax({
            type:"get",
            url:"/getSession",
            success(res){
                
                if(!res.username){
                    // location.href = "#login";
                    return;
                }
                $("#username").html(res.username);
            }
        });
       $("#logout").click(function(){
            $.ajax({
                type:"get",
                url:"/removeSession",
                success(){
                    location.href = "#login";
                }
            });
       })
        next();
        // element.render();
        // element.on('nav(studentNav)',function(data){
        //     let hash = data.attr('href');
        //     if(hash == "#student"){
        //         new Student();
        //     }
        // });
    }
}